/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.googlecode.oskis.library.db;
import java.sql.*;


/**
 * Klasse zum finden von Postleitzahlen und Orten
 * @author thomas
 */
public class PLZFinder {
    
    private Connection db;
    private String plz;
    private String ort;
    
    public PLZFinder(Connection db) {
        this.db=db;        
        plz="";
        ort="";
    }
    
    public PLZFinder(Connection db,String splz) {
        this.db=db;
        this.plz=splz;
        this.ort="";
        findOrt(plz);
    }
    
    public void findOrt(String splz) {
        String SQL="select name from xloc l,xplz p " +
                "     where l.loc=p.loc" +
                "     and p.plz='"+splz+"'";
        try {
            Statement st=db.createStatement();
            ResultSet rs=st.executeQuery(SQL);
            if (rs.next()) {
               ort=rs.getString("name"); 
            }
            rs.close();
            st.close();
        } catch (SQLException e) {
            e.printStackTrace();
            ort="";
        }
    }

    public String getOrt() {
        return(ort);
    }
    
}
